﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.WishlistUI {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import Events.*;
    import org.aswing.*;
    import Transactions.*;
    import Classes.util.*;
    import flash.filters.*;
    import org.aswing.geom.*;
    import Display.*;
    import Display.MarketUI.*;
    import Display.InventoryUI.*;
    import Display.aswingui.*;

    public class WishlistCell extends DataItemCell {

        public static const OVERLAP_AMOUNT:int = 28;

        protected var m_itemIconPane:JPanel;
        protected var m_removePane:JPanel;
        protected var m_removeButton:JButton;
        protected var m_slotSize:IntDimension;
        protected var m_slotOffset:int;
        protected var m_initialized:Boolean = false;
        protected var m_content:DisplayObject;
        protected var m_bgDec:MarginBackground;

        public function WishlistCell(_arg1:LayoutManager=null, _arg2:IntDimension=null, _arg3:int=2){
            super(new SoftBoxLayout(SoftBoxLayout.Y_AXIS, 0, SoftBoxLayout.CENTER));
            if (_arg2){
                this.m_slotSize = _arg2;
            } else {
                this.m_slotSize = new IntDimension(Catalog.CARD_WIDTH, Catalog.CARD_HEIGHT);
            };
            this.m_slotOffset = _arg3;
            setPreferredSize(this.m_slotSize);
        }
        override protected function scaleToFit(_arg1:DisplayObject):Number{
            var _local2:Number = 1;
            var _local3:Number = 1;
            return (Math.min(_local2, _local3));
        }
        override public function setCellValue(_arg1):void{
            m_item = _arg1;
            var _local2:String = Global.gameSettings.getImageByName(m_item.name, "icon");
            if (_local2 != null){
                m_loader = LoadingManager.load(_local2, onIconLoad, LoadingManager.PRIORITY_HIGH);
            } else {
                this.initializeCell();
            };
        }
        override protected function initializeCell():void{
            var _local5:Number;
            var _local6:DisplayObject;
            var _local7:DisplayObject;
            var _local8:DisplayObject;
            var _local9:JPanel;
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(AsWingConstants.CENTER);
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanel(AsWingConstants.CENTER);
            var _local3:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            if (m_item.name == "blankItem"){
                this.m_content = (new (InventoryView.assetDict["inventory_card_locked"])() as DisplayObject);
            } else {
                this.m_content = (new (InventoryView.assetDict["inventory_card"])() as DisplayObject);
            };
            ASwingHelper.setSizedBackground(_local3, this.m_content);
            this.m_itemIconPane = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            var _local4:AssetPane = new AssetPane(m_itemIcon);
            ASwingHelper.prepare(_local4);
            if (((!((m_item.name == "blankItem"))) && (m_itemIcon))){
                _local5 = ((this.m_content.width - m_itemIcon.width) / 2);
                ASwingHelper.setEasyBorder(_local4, 0, _local5);
            };
            this.m_itemIconPane.append(_local4);
            ASwingHelper.prepare(this.m_itemIconPane);
            _local3.append(this.m_itemIconPane);
            ASwingHelper.prepare(_local3);
            _local2.append(_local3);
            if (m_item.name != "blankItem"){
                _local6 = (new (InventoryView.assetDict["btn_close_small_up"])() as DisplayObject);
                _local7 = (new (InventoryView.assetDict["btn_close_small_over"])() as DisplayObject);
                _local8 = (new (InventoryView.assetDict["btn_close_small_down"])() as DisplayObject);
                _local9 = ASwingHelper.makeSoftBoxJPanelVertical(AsWingConstants.TOP);
                this.m_removePane = ASwingHelper.makeSoftBoxJPanel(AsWingConstants.RIGHT);
                this.m_removeButton = new JButton();
                this.m_removeButton.wrapSimpleButton(new SimpleButton(_local6, _local7, _local8, _local6));
                this.m_removeButton.setFont(ASwingHelper.getBoldFont(12));
                this.m_removeButton.setForeground(new ASColor(0xFFFFFF));
                this.m_removeButton.filters = [new GlowFilter(0)];
                this.m_removeButton.addEventListener(MouseEvent.MOUSE_UP, this.onRemove, false, 0, true);
                this.m_removePane.append(this.m_removeButton);
                ASwingHelper.prepare(this.m_removePane);
                _local9.append(this.m_removePane);
                ASwingHelper.prepare(_local9);
                _local2.append(ASwingHelper.horizontalStrut(-(_local6.width)));
                _local2.append(_local9);
            };
            ASwingHelper.prepare(_local2);
            _local1.append(ASwingHelper.horizontalStrut(WishlistView.GRID_MARGIN));
            _local1.append(_local2);
            _local1.append(ASwingHelper.horizontalStrut(WishlistView.GRID_MARGIN));
            ASwingHelper.prepare(_local1);
            this.append(_local1);
            ASwingHelper.prepare(this);
            this.m_initialized = true;
        }
        protected function onRemove(_arg1:MouseEvent):void{
            GameTransactionManager.addTransaction(new TRemoveFromWishlist(m_item.name));
            dispatchEvent(new DataItemEvent(DataItemEvent.WISHLIST_CHANGED, m_item, null, true));
        }

    }
}//package Display.WishlistUI 
